[converter] implement aten::atan2 conversion - #23
Merged
gokulkrishna98 merged 8 commits intoJul 8, 2026
Conversation
Adds a converter for aten.atan2.default. coreai has no native atan2 op, so the conversion decomposes it into atan(y/x) with per-quadrant correction: - x > 0: atan(y/x) - x < 0, y ≥ 0: atan(y/x) + π - x < 0, y < 0: atan(y/x) − π - x = 0, y > 0: π/2 - x = 0, y < 0: −π/2 - x = 0, y = 0: 0 Division by zero when x=0 is guarded with broadcasting_where before the divide, then the x=0 result is selected in a final where at the end. Adds numerical tests (shapes 1D/2D/3D, float32/float16, static/dynamic, axis-aligned edge cases) and IR FileCheck tests (static, dynamic, 1D).
Accidentally dropped when TestAtan2 was inserted at the same location.
gokulkrishna98
marked this pull request as ready for review
June 22, 2026 22:59
- Document IEEE-754 limitations (signed zeros, infinities) in replace_atan2 docstring - Add (0, 0) case to test_x_zero to lock in atan2(0, 0) = 0 by convention
- Signed zeros: use 1/v trick (1/-0.0 = -inf) combined with strict > to make y_neg and x_neg correct for -0.0 inputs without misclassifying ±inf values which use the strict > path directly - x = -0.0 branch: split x=0 into +0 (returns ±π/2) and -0 (returns ±π) per IEEE-754 atan2 specification - Both infinite: add explicit branch for atan2(±inf, ±inf) → ±π/4 or ±3π/4; previously produced NaN via atan(inf/inf) = atan(NaN) - Add test_signed_zeros and test_infinities to lock in correct behaviour - Update IR tests to reflect the expanded op sequence
gokulkrishna98
force-pushed
the
dev/gokul/atan2-support
branch
from
June 23, 2026 03:19
8035ea1 to
5e2a2d7
Compare
gokulkrishna98
requested review from
Lewis300,
TobyRoseman,
YifanShenSZ and
cymbalrush
July 7, 2026 19:03
TobyRoseman
reviewed
Jul 7, 2026
jakesabathia2
approved these changes
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a converter for aten.atan2.default. coreai has no native atan2 op, so the conversion decomposes it into atan(y/x) with per-quadrant correction:
Division by zero when x=0 is guarded with broadcasting_where before the divide, then the x=0 result is selected in a final where at the end.
Testing: